package com.xxxx.server.controller;




import com.xxxx.server.mapper.SalaryMapper;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Salary;
import com.xxxx.server.service.impl.SalaryServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Resource
    private SalaryServiceImpl salaryService;

    //1111111111111111111111111
    @ApiOperation(value = "查询所有员工套账")
    @GetMapping
    public List<Salary> selectAll(){
        List<Salary> salaries = salaryService.list();
        return salaries;
    }

    @ApiOperation(value = "添加员工套账")
    @PostMapping("/")
    public RespBean addSalary(@RequestBody Salary salary){
        //设置创建时间
        salary.setCreateDate(LocalDateTime.now());
        //添加
        boolean save = salaryService.save(salary);
        if(save){
            return RespBean.success("添加员工账套成功");
        }else{
            return RespBean.error("添加员工账套失败");
        }
    }

    @ApiOperation(value = "删除员工套账")
    @DeleteMapping("/{id}")
    public RespBean removeById(@PathVariable Integer id){
        //删除
        boolean removeById = salaryService.removeById(id);
        if(removeById){
            return RespBean.success("删除员工账套成功");
        }else{
            return RespBean.error("删除员工账套失败");
        }
    }

    @ApiOperation(value = "更新员工套账")
    @PutMapping()
    public RespBean updateById(@RequestBody Salary salary){
        //更新
        boolean updateById = salaryService.updateById(salary);
        if(updateById){
            return RespBean.success("更新员工账套成功");
        }else{
            return RespBean.error("更新员工账套失败");
        }
    }

}
